extends Player_Class

signal player_info_update
signal player_upgrade
var is_flip = true
var can_move = true

func flash():
	$AnimatedSprite2D.material.set_shader_parameter("flash_opacity",1)
	await get_tree().create_timer(0.1).timeout
	$AnimatedSprite2D.material.set_shader_parameter("flash_opacity",0)

func update_info():
	if cur_hp <= 0:
		die()
		return
	hurt = basic_hurt*(1+basic_hurt_multiple)
	total_hp = max_hp + hp_get
	if cur_exp >= max_exp:
		level += 1
		max_hp = max_hp * max_hp_rate
		max_exp = max_exp * max_exp_rate
		total_hp = max_hp + hp_get
		cur_hp = total_hp
		player_upgrade.emit()
	player_info_update.emit()

func die():
	pass

func _ready() -> void:
	input_pickable = true

func _physics_process(delta: float) -> void:
	var mouse_pos = get_global_mouse_position()
	if can_move:
		if global_position.x < mouse_pos.x:
			is_flip = false
		else:
			is_flip = true
		$AnimatedSprite2D.flip_h = is_flip
		velocity = global_position.direction_to(mouse_pos) * speed
		move_and_slide()


func _on_mouse_entered() -> void:
	can_move = false
	pass # Replace with function body.


func _on_mouse_exited() -> void:
	can_move = true
	pass # Replace with function body.


func _on_area_2d_body_entered(body):
	if body.is_in_group("item"):
		print(111)
		gold += 1 + gold_get
		body.queue_free()
		update_info()
	pass # Replace with function body.
